from django.core.management.base import BaseCommand
from delivery.service.delivery_generate import generate_and_save_delivery

class Command(BaseCommand):
    help = '执行补货建议生成服务'

    def handle(self, *args, **options):
        try:
            self.stdout.write(self.style.SUCCESS('开始生成补货建议...'))
            result = generate_and_save_delivery()
            
            if result['success']:
                self.stdout.write(
                    self.style.SUCCESS(f'补货建议生成成功: {result["message"]}')
                )
            else:
                self.stdout.write(
                    self.style.ERROR(f'补货建议生成失败: {result["message"]}')
                )
                
        except Exception as e:
            self.stdout.write(self.style.ERROR(f'执行失败: {str(e)}'))